#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define _COMPILER

#define MAX(a, b) (a < b ? b : a)
#define MIN(a, b) (a < b ? a : b)

// Errors and warnings
#define WARNING(s, sextra)		{ fprintf(stderr, "Warning! Message: " s " \n", sextra); }
#define MESSAGE(s, sextra)		{ fprintf(stdout, "Message: " s " \n", sextra); }
#define ERROR(s, sextra, code)	{ fprintf(stderr, "Error: " s " \n", sextra); exit(code); }

#define ERROR_FATAL 1
#define ERROR_INPUT 2
#define ERROR_ARGS 3
#define ERROR_DISK 4

// Basic structs
struct options
{
	unsigned int optimization : 1;
	unsigned int verbose : 1;
};

// Linked list

#define LINKED_LIST(ID,T) \
struct linked_list_##ID \
{\
	T data;\
struct linked_list_##ID *next, *prev;\
} root_##ID;\
	\
struct linked_list_##ID *linked_list_add_##ID(struct linked_list_##ID *root, T data)\
{\
struct linked_list_##ID *block = (struct linked_list_##ID *)malloc(sizeof(struct linked_list_##ID##));\
	if (block == NULL) {\
	ERROR("malloc failed at line %d", __LINE__, ERROR_FATAL);\
	}\
	block->data = data;\
	block->next = root;\
	block->prev = 0;\
	if (root != 0) {\
	block->prev = root->prev;\
	root->prev = block;\
	}\
	root = block;\
	return root;\
}

#define LINKED_LIST_STRUCT(ID) struct linked_list_##ID
#define LINKED_LIST_ADD(ID, root, data) root = linked_list_add_##ID(root, data);